﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Globalization;
using System.Data;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Common;
 

namespace MockPrjTeam4.DAO
{
    public class ContactTypeDAO
    {
        public static ContactType GetListContactTypeObjects(IDataRecord read)
        {
            if (read == null)
                return null;
            return new ContactType
            {
                ContactTypeId = Methods.ConvertNumber(read[ContactType.FieldContactTypeId].ToString()),
                ContactTypeName = Methods.ConvertString(read[ContactType.FieldContactTypeName].ToString())
            };
        }

        public static IList<ContactType> ListContactType()
        {
            List<ContactType> listContactType = new List<ContactType>();
            var query = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM ContactType");
            using(var reader = SqlHelper.ExecuteReader(query))
            {
                try
                {
                    while (reader.Read())
                    {
                        listContactType.Add(GetListContactTypeObjects(reader));
                    }
                    return listContactType;
                }
                catch (System.Exception ex)
                {
                    return null;
                }
            }
        }
    }
}